﻿using System.Collections.Generic;
using System.Linq;
using FoodRaidersWebAPI.domainnew.other;
using FoodRaidersWebAPI.Models;
using FoodRaidersWebAPI.Service.Third;

namespace FoodRaidersWebAPI.Service.Second
{
    public class MerchantService
    {
        private readonly FoodContext context;
        private readonly DashService dashService;
        
        public MerchantService(FoodContext context)
        {
            this.context = context;
            dashService = new DashService(context);
        }
        //删除
        public Merchant delete(int id)
        {
            var merchant = findByID(id);
            context.Merchants.Remove(merchant);
            context.SaveChanges();
            return merchant;
        }
        //id查询 对象不加载
        public Merchant findByID(int id)
        {
            return context.Merchants.FirstOrDefault(m => m.MerchantID == id);
        }
        //id查询 全加载
        public Merchant findByIDFullLoad(int id)
        {
            var merchant = findByID(id);
            context.Entry(merchant).Collection(m=>m.Dashes).Load();
            return merchant;
        }
    }
}